package com.pxx.search.controller;

import com.item.common.PageResult;
import com.pxx.search.pojo.GoodsEs;
import com.pxx.search.pojo.SearchRequest;
import com.pxx.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SearchController {

    @Autowired
    SearchService searchService;

    @PostMapping("/page")
    public ResponseEntity<PageResult<GoodsEs>> search(@RequestBody SearchRequest searchRequest){
        PageResult<GoodsEs> page =  searchService.search(searchRequest);
        if (page == null){
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }

        return ResponseEntity.ok(page);
    }
}
